Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents LstDVDs As System.Windows.Forms.ListBox Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox Friend WithEvents Label3 As System.Windows.Forms.Label Friend WithEvents TxtDVD As System.Windows.Forms.TextBox Friend WithEvents TxtPrice As System.Windows.Forms.TextBox Friend WithEvents Label4 As System.Windows.Forms.Label Friend WithEvents TxtTax As System.Windows.Forms.TextBox Friend WithEvents Label5 As System.Windows.Forms.Label Friend WithEvents txtTotal As System.Windows.Forms.TextBox Friend WithEvents Label6 As System.Windows.Forms.Label Friend WithEvents BtnPay As System.Windows.Forms.Button Friend WithEvents BtnClear As System.Windows.Forms.Button Friend WithEvents BtnQuit As System.Windows.Forms.Button Friend WithEvents BtnSum As System.Windows.Forms.Button Friend WithEvents LstTotals As System.Windows.Forms.ListBox Friend WithEvents Label7 As System.Windows.Forms.Label Friend WithEvents Label8 As System.Windows.Forms.Label Friend WithEvents LstMovies As System.Windows.Forms.ListBox Friend WithEvents Grpresults As System.Windows.Forms.GroupBox Private Sub InitializeComponent() Me.Label1 = New System.Windows.Forms.Label Me.LstDVDs = New System.Windows.Forms.ListBox Me.Label2 = New System.Windows.Forms.Label Me.GroupBox1 = New System.Windows.Forms.GroupBox Me.BtnQuit = New System.Windows.Forms.Button Me.BtnClear = New System.Windows.Forms.Button Me.BtnPay = New System.Windows.Forms.Button Me.txtTotal = New System.Windows.Forms.TextBox Me.Label6 = New System.Windows.Forms.Label Me.TxtTax = New System.Windows.Forms.TextBox Me.Label5 = New System.Windows.Forms.Label Me.TxtPrice = New System.Windows.Forms.TextBox Me.Label4 = New System.Windows.Forms.Label Me.TxtDVD = New System.Windows.Forms.TextBox Me.Label3 = New System.Windows.Forms.Label Me.BtnSum = New System.Windows.Forms.Button Me.Grpresults = New System.Windows.Forms.GroupBox Me.LstTotals = New System.Windows.Forms.ListBox Me.LstMovies = New System.Windows.Forms.ListBox Me.Label7 = New System.Windows.Forms.Label Me.Label8 = New System.Windows.Forms.Label Me.GroupBox1.SuspendLayout() Me.Grpresults.SuspendLayout() Me.SuspendLayout() ' 'Label1 ' Me.Label1.AutoSize = True Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 18.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label1.Location = New System.Drawing.Point(296, 8) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(173, 37) Me.Label1.TabIndex = 0 Me.Label1.Text = "DVDs R Us" ' 'LstDVDs ' Me.LstDVDs.ItemHeight = 16 Me.LstDVDs.Location = New System.Drawing.Point(40, 80) Me.LstDVDs.Name = "LstDVDs" Me.LstDVDs.Size = New System.Drawing.Size(312, 180) Me.LstDVDs.TabIndex = 1 ' 'Label2 ' Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label2.Location = New System.Drawing.Point(32, 48) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(240, 32) Me.Label2.TabIndex = 2 Me.Label2.Text = "Choose DVD:" ' 'GroupBox1 ' Me.GroupBox1.Controls.Add(Me.BtnQuit) Me.GroupBox1.Controls.Add(Me.BtnClear) Me.GroupBox1.Controls.Add(Me.BtnPay) Me.GroupBox1.Controls.Add(Me.txtTotal) Me.GroupBox1.Controls.Add(Me.Label6) Me.GroupBox1.Controls.Add(Me.TxtTax) Me.GroupBox1.Controls.Add(Me.Label5) Me.GroupBox1.Controls.Add(Me.TxtPrice) Me.GroupBox1.Controls.Add(Me.Label4) Me.GroupBox1.Controls.Add(Me.TxtDVD) Me.GroupBox1.Controls.Add(Me.Label3) Me.GroupBox1.Location = New System.Drawing.Point(408, 56) Me.GroupBox1.Name = "GroupBox1" Me.GroupBox1.Size = New System.Drawing.Size(352, 352) Me.GroupBox1.TabIndex = 3 Me.GroupBox1.TabStop = False Me.GroupBox1.Text = "Purchase Info" ' 'BtnQuit ' Me.BtnQuit.Location = New System.Drawing.Point(240, 240) Me.BtnQuit.Name = "BtnQuit" Me.BtnQuit.Size = New System.Drawing.Size(96, 40) Me.BtnQuit.TabIndex = 10 Me.BtnQuit.Text = "Quit" ' 'BtnClear ' Me.BtnClear.Location = New System.Drawing.Point(128, 240) Me.BtnClear.Name = "BtnClear" Me.BtnClear.Size = New System.Drawing.Size(96, 40) Me.BtnClear.TabIndex = 9 Me.BtnClear.Text = "Clear" ' 'BtnPay ' Me.BtnPay.Location = New System.Drawing.Point(16, 240) Me.BtnPay.Name = "BtnPay" Me.BtnPay.Size = New System.Drawing.Size(96, 40) Me.BtnPay.TabIndex = 8 Me.BtnPay.Text = "Pay" ' 'txtTotal ' Me.txtTotal.Location = New System.Drawing.Point(136, 176) Me.txtTotal.Name = "txtTotal" Me.txtTotal.ReadOnly = True Me.txtTotal.Size = New System.Drawing.Size(192, 22) Me.txtTotal.TabIndex = 7 Me.txtTotal.Text = "" ' 'Label6 ' Me.Label6.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label6.Location = New System.Drawing.Point(16, 176) Me.Label6.Name = "Label6" Me.Label6.Size = New System.Drawing.Size(136, 32) Me.Label6.TabIndex = 6 Me.Label6.Text = "Total:" ' 'TxtTax ' Me.TxtTax.Location = New System.Drawing.Point(136, 128) Me.TxtTax.Name = "TxtTax" Me.TxtTax.ReadOnly = True Me.TxtTax.Size = New System.Drawing.Size(192, 22) Me.TxtTax.TabIndex = 5 Me.TxtTax.Text = "" ' 'Label5 ' Me.Label5.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label5.Location = New System.Drawing.Point(16, 128) Me.Label5.Name = "Label5" Me.Label5.Size = New System.Drawing.Size(136, 32) Me.Label5.TabIndex = 4 Me.Label5.Text = "Tax:" ' 'TxtPrice ' Me.TxtPrice.Location = New System.Drawing.Point(136, 80) Me.TxtPrice.Name = "TxtPrice" Me.TxtPrice.ReadOnly = True Me.TxtPrice.Size = New System.Drawing.Size(192, 22) Me.TxtPrice.TabIndex = 3 Me.TxtPrice.Text = "" ' 'Label4 ' Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label4.Location = New System.Drawing.Point(16, 80) Me.Label4.Name = "Label4" Me.Label4.Size = New System.Drawing.Size(136, 32) Me.Label4.TabIndex = 2 Me.Label4.Text = "DVD Price:" ' 'TxtDVD ' Me.TxtDVD.Location = New System.Drawing.Point(136, 40) Me.TxtDVD.Name = "TxtDVD" Me.TxtDVD.ReadOnly = True Me.TxtDVD.Size = New System.Drawing.Size(192, 22) Me.TxtDVD.TabIndex = 1 Me.TxtDVD.Text = "" ' 'Label3 ' Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label3.Location = New System.Drawing.Point(16, 40) Me.Label3.Name = "Label3" Me.Label3.Size = New System.Drawing.Size(136, 32) Me.Label3.TabIndex = 0 Me.Label3.Text = "DVD Name:" ' 'BtnSum ' Me.BtnSum.Location = New System.Drawing.Point(40, 272) Me.BtnSum.Name = "BtnSum" Me.BtnSum.Size = New System.Drawing.Size(88, 40) Me.BtnSum.TabIndex = 4 Me.BtnSum.Text = "Show Summary" ' 'Grpresults ' Me.Grpresults.Controls.Add(Me.Label8) Me.Grpresults.Controls.Add(Me.Label7) Me.Grpresults.Controls.Add(Me.LstMovies) Me.Grpresults.Controls.Add(Me.LstTotals) Me.Grpresults.Location = New System.Drawing.Point(32, 328) Me.Grpresults.Name = "Grpresults" Me.Grpresults.Size = New System.Drawing.Size(360, 280) Me.Grpresults.TabIndex = 5 Me.Grpresults.TabStop = False Me.Grpresults.Text = "Summary of Sales" Me.Grpresults.Visible = False ' 'LstTotals ' Me.LstTotals.ItemHeight = 16 Me.LstTotals.Location = New System.Drawing.Point(224, 40) Me.LstTotals.Name = "LstTotals" Me.LstTotals.Size = New System.Drawing.Size(88, 228) Me.LstTotals.TabIndex = 0 ' 'LstMovies ' Me.LstMovies.ItemHeight = 16 Me.LstMovies.Location = New System.Drawing.Point(16, 40) Me.LstMovies.Name = "LstMovies" Me.LstMovies.Size = New System.Drawing.Size(192, 228) Me.LstMovies.TabIndex = 1 ' 'Label7 ' Me.Label7.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label7.Location = New System.Drawing.Point(40, 16) Me.Label7.Name = "Label7" Me.Label7.Size = New System.Drawing.Size(144, 16) Me.Label7.TabIndex = 2 Me.Label7.Text = "Movie" ' 'Label8 ' Me.Label8.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label8.Location = New System.Drawing.Point(224, 16) Me.Label8.Name = "Label8" Me.Label8.Size = New System.Drawing.Size(120, 16) Me.Label8.TabIndex = 3 Me.Label8.Text = "Number Sold" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15) Me.ClientSize = New System.Drawing.Size(824, 624) Me.Controls.Add(Me.Grpresults) Me.Controls.Add(Me.BtnSum) Me.Controls.Add(Me.GroupBox1) Me.Controls.Add(Me.Label2) Me.Controls.Add(Me.LstDVDs) Me.Controls.Add(Me.Label1) Me.Name = "Form1" Me.Text = "DVDs R Us" Me.GroupBox1.ResumeLayout(False) Me.Grpresults.ResumeLayout(False) Me.ResumeLayout(False) End Sub #End Region Dim inpf As IO.StreamReader Dim outf As IO.StreamWriter Const taxRate As Double = 0.07 ' declare arrays - need it to be bigger than would ever need it Dim totals(1000) As Integer Dim movies(1000) As String Dim numDVDs As Integer Dim currDVD As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim nextDVD As String ' load list box from file If IO.File.Exists("DVDs.txt") Then ' file exists, loop until end of file inpf = IO.File.OpenText("DVDs.txt") Do While inpf.Peek() <> -1 nextDVD = inpf.ReadLine() LstDVDs.Items.Add(nextDVD) ' pull movie name out of line read and stick in array for safekeeping Dim commapos As Integer = nextDVD.IndexOf(","c) ' pull out movie title from before comma movies(numDVDs) = nextDVD.Substring(0, commapos) ' update number of dvds numDVDs = numDVDs + 1 Loop inpf.Close() Else MsgBox("Sorry, list of DVDs not found. Please create a file named DVDs.txt in the bin folder") Me.Close() End If End Sub Private Sub LstDVDs_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LstDVDs.SelectedIndexChanged Dim strLine As String strLine = LstDVDs.SelectedItem currDVD = LstDVDs.SelectedIndex ' keep track of which item selected - in global variable so buy handler knows index number strLine = strLine.Trim Dim movie As String Dim price As Double Dim tax As Double Dim total As Double ' find where in line the comma is Dim commapos As Integer = strLine.IndexOf(","c) ' pull out movie title from before comma movie = strLine.Substring(0, commapos) ' pull out price from after comma price = Convert.ToDouble(strLine.Substring(commapos + 1).Trim()) 'MsgBox(movie & " selected - cost is: " & price) TxtDVD.Text = movie TxtPrice.Text = price.ToString("c") tax = price * taxRate TxtTax.Text = tax.ToString("c") total = price + tax txtTotal.Text = total.ToString("c") End Sub Private Sub BtnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnQuit.Click Me.Close() End Sub Private Sub BtnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClear.Click TxtDVD.Text = "" TxtPrice.Text = "" TxtTax.Text = "" txtTotal.Text = "" End Sub Private Sub BtnPay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPay.Click MsgBox("In real system, this would proceed to form for payment - e.g. handle credit card") ' establish output file outf = IO.File.AppendText("sales.txt") outf.WriteLine(" " & TxtDVD.Text & ", " & TxtPrice.Text & ", " & _ TxtTax.Text & ", " & txtTotal.Text) outf.Close() ' update count of sales for the movie totals(currDVD) = totals(currDVD) + 1 End Sub Private Sub BtnSum_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSum.Click Dim mov As Integer ' first clear out any previous results LstMovies.Items.Clear() LstTotals.Items.Clear() For mov = 0 To numDVDs - 1 LstMovies.Items.Add(movies(mov)) LstTotals.Items.Add(totals(mov)) Next mov ' make the info visible Grpresults.Visible = True End Sub End Class